package com.api.shopapi.mapper;



import com.api.shopapi.entity.ElderlyClass;
import com.api.shopapi.entity.dto.ElderlyClassDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ElderlyClassMapper {
    @Insert("insert into elderly_class " +
            "(" +
            "ElderlyClassCode," +
            "Name," +
            "Value," +
            "Sort," +
            "Status," +
            "AddBalance," +
            "StaffCode," +
            "GovernmentCode" +
            ") " +
            "value " +
            "(" +
            "#{elderlyClass.ElderlyClassCode}," +
            "#{elderlyClass.Name}," +
            "#{elderlyClass.Value}," +
            "#{elderlyClass.Sort}," +
            "#{elderlyClass.Status}," +
            "#{elderlyClass.AddBalance}," +
            "#{elderlyClass.StaffCode}," +
            "#{elderlyClass.GovernmentCode})")
    int insert(@Param("elderlyClass") ElderlyClass elderlyClass);

    @Update("update elderly_class " +
            "set " +
            "Name = #{elderlyClass.Name}," +
            "Value = #{elderlyClass.Value}," +
            "Sort=#{elderlyClass.Sort}," +
            "Status = #{elderlyClass.Status}," +
            "AddBalance=#{elderlyClass.AddBalance}," +
            "StaffCode=#{elderlyClass.StaffCode}," +
            "GovernmentCode=#{elderlyClass.GovernmentCode} " +
            "where " +
            "ElderlyClassCode=#{elderlyClass.ElderlyClassCode}")
    int update(@Param("elderlyClass") ElderlyClass elderlyClass);


    @Select("select  * from  elderly_class order by GovernmentCode desc ")
    List<ElderlyClassDTO> getListPage();

    @Select("select  * from  elderly_class where Value=#{value} and GovernmentCode=#{governmentCode} limit 1 ")
    ElderlyClass getByValue(@Param("value") int value,@Param("governmentCode") String governmentCode);

    @Select("select  * from elderly_class where Name=#{name} and GovernmentCode=#{governmentCode} limit 1 ")
    ElderlyClass getByName(@Param("name") String name,@Param("governmentCode") String governmentCode);


    @Delete("delete from elderly_class " +
            "where " +
            "ElderlyClassCode=#{elderlyClassCode}")
    int delete(@Param("elderlyClassCode") String elderlyClassCode);

    @Select("select * from elderly_class " +
            " where " +
            " GovernmentCode = #{governmentCode} " +
            " order by Sort desc")
    List<ElderlyClass> getList(@Param("governmentCode")String governmentCode);


    @Select("select * from elderly_class " +
            "where " +
            "ElderlyClassCode=#{elderlyClassCode} limit 1")
    ElderlyClass getByElderlyClassCode(@Param("elderlyClassCode") String elderlyClassCode);

    @Select("select * from elderly_class " +
            "where Name=#{name} " +
            "and " +
            "GovernmentCode=#{governmentCode} " +
            "limit 1")
    ElderlyClass getByNameAndGovernmentCode(@Param("name") String name,@Param("governmentCode") String governmentCode);

    @Select("<script>" +
            "select * from elderly_class " +
            "where GovernmentCode = #{governmentCode} " +
            "<if test ='name !=null'>" +
            "and Name like concat('%',#{name},'%') " +
            "</if>" +
            "order by Sort desc" +
            "</script>")
    List<ElderlyClass> getPageList(@Param("name") String name, @Param("governmentCode")String governmentCode);

    @Select("select * from elderly_class " +
            "where " +
            "StaffCode=#{staffCode} ")
    ElderlyClass getByStaffCode(@Param("staffCode") String staffCode);

    @Select("select * from  elderly_class where GovernmentCode=#{governmentCode} and Value=#{value}  limit 1")
    ElderlyClass getByValueAndGovernmentCode(@Param("value") int value,
                                             @Param("governmentCode") String governmentCode);







}
